package com.asiainfo.dacp.datastash.domain.stepdefine.service;

import com.asiainfo.dacp.datastash.domain.stepdefine.models.DataStashStepDefine;
import com.asiainfo.dacp.datastash.domain.stepdefine.repos.DataStashStepDefineRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by winter on 2017/12/27.
 */
@Service
public class DataStashStepDefineService {

    @Autowired
    private DataStashStepDefineRepository stepDefineRepo;
    @Autowired
    private DataStashStepDefineStepCfgService stepCfgService;

    public List<DataStashStepDefine> findAll()throws Exception{
        List<DataStashStepDefine> defines= stepDefineRepo.findAll();
        if(defines.size()<=0){
            return  null;
        }
        for(DataStashStepDefine define:defines){
           String stepCfg=  define.getStepCfg();
           if(StringUtils.isNotBlank(stepCfg)&&stepCfg.contains("optionClass")){
               define.setStepCfg(stepCfgService.initOptions(stepCfg));
           }
        }
        return  defines;
    }



}